const mysql = require('mysql')
const GenId = require('../utils/SnowFlake')

const genid = new GenId({WorkerId: 1})

db = mysql.createPool({
    host: '127.0.0.1',
    user: 'root',
    password: 'admin123',  // 这里使用自己数据库的密码
    database: 'blog'
})

db.async = {}
db.async.query = (sql, params) => {
    return new Promise((resolve, reject) => {
        db.query(sql, params, (err, results) => {
            resolve({err, results})
        })
    })
}

module.exports = {db, genid}